#coding=utf-8
import redis
import datetime
from  config import *
import time 
import datetime
class RedisManager(object):
    def __init__(self):
	pool = None
	rds  = None
    def conn(self):
	#self.pool = redis.ConnectionPool(host='127.0.0.1',port = 6379,password=123)
	self.pool = redis.ConnectionPool(host='127.0.0.1',port = 6379)
	self.rds= redis.Redis(connection_pool=self.pool)
    def rset(self):

	self.rds.set('name','cpr')
	print self.rds.get('name')

def judge():
    whichday = datetime.datetime.now().weekday()
    if whichday <5:
        return "weekday"
    else :
        return "weekend"
if __name__ == '__main__':
     
    redisM = RedisManager()
    redisM.conn()
    mid = 1
    tradekey = "%s%d"%(base_midtradekey,mid) 
    tradeinfo = redisM.rds.hgetall(tradekey)
    daytype = judge()
    newtradeinfo = eval(tradeinfo[daytype])
    print newtradeinfo
    special=newtradeinfo["special"]
    default=newtradeinfo["default"]
    #当前时间
    nowtime = time.strftime("%H:%M:%S") ##24小时格式
    packs = []
    for row in special :
        if nowtime >row["start_time"] and nowtime<row["end_time"]:
	    packs = row["trade"]
	    break
    if not packs :	    
        packs = default["trade"] 
    print packs
